#ifndef TD_MATRIX2D_H_
#define TD_MATRIX2D_H_

#include "Coord2D.h"

namespace TD_Core {

	class Matrix2D {

	public:
		
		int * m_matrix;
		Coord2D m_matrixSize;
		
		/************************************************************************/
		/* Private functions                                                    */
		/************************************************************************/
		inline void allocateMem() {

			m_matrix = new int[m_matrixSize.x*m_matrixSize.y];
		}
		
	public:

		/************************************************************************/
		/* ctors and dtors				                                        */
		/************************************************************************/
		
		//Constructor default
		inline explicit Matrix2D() {
			m_matrix = 0;
		}
		//Copy constructor
		inline explicit Matrix2D(const Matrix2D &rhs) {
			m_matrix = rhs.m_matrix;
		}
		//Assignment constructor
		Matrix2D inline & operator=(const Matrix2D &rhs) {
			m_matrix = rhs.m_matrix;
			return(*this);
		}

		//Initialization constructors 
		inline explicit Matrix2D(const Coord2D & matrixSize) {
			m_matrixSize = matrixSize;
			allocateMem();
		}

		inline explicit Matrix2D(unsigned int i, unsigned int j) {
			m_matrixSize.x = i;
			m_matrixSize.y = j;
			allocateMem();
		}
		
		//Destructor
		~Matrix2D() {
			delete[] m_matrix;
		}


		/************************************************************************/
		/* Access functions                                                     */
		/************************************************************************/

		inline int & operator() (unsigned int row, unsigned int column) {
			return(m_matrix[row*m_matrixSize.x + column]);
		}
		
		inline int operator() (unsigned int row, unsigned int column) const {
			return(m_matrix[row*m_matrixSize.x + column]);
		}

		inline int * getRawMatrix() {
			return (m_matrix);
		}

		inline const Coord2D & getMatrixSize() const {
			return(m_matrixSize);
		}

	};

}


#endif